/*
import { createStore } from 'vuex';
import type { Commit } from 'vuex'; // 新增类型导入

// 定义状态类型
interface State {
  isCollapsed: boolean;
}

// 创建 Vuex store
const store = createStore<State>({
  state(): State {
    return {
      isCollapsed: false,  // 初始状态
      messages: [] as Message[],
    };
  },
  mutations: {
    toggleSidebar(state: State) {
      state.isCollapsed = !state.isCollapsed;  // 切换侧边栏收缩状态
    },
  },
  actions: {
    toggleSidebar({ commit }: { commit: Commit }) {
      commit('toggleSidebar');  // 提交 mutation 切换状态
    },
  },
  getters: {
    isCollapsed(state: State): boolean {
      return state.isCollapsed;  // 获取 isCollapsed 状态
    },
  },
});

export default store;
*/

import { createStore } from 'vuex'
import type { Commit } from 'vuex' // 新增类型导入

// 定义状态类型
interface State {
  isCollapsed: boolean
  messages: Message[] // 添加 messages 属性
}

interface Message {
  id: number
  text: string
  sender: 'User' | 'Claude'
}

// 创建 Vuex store
const store = createStore<State>({
  state(): State {
    return {
      isCollapsed: false, // 初始状态
      messages: [
        {
            id: 1,
            text: "Hello! I'm Claude, an AI assistant created by Anthropic.",
            sender: 'Claude'
        },
        {
            id: 2,
            text: "How can I help you to1111111111111111111111day?",
            sender: 'User'
        },
        {
            id: 3,
            text: "How can I help you to1111111111111111111111day?",
            sender: 'Claude'
        },
        {
            id: 4,
            text: "How can I he1222222222222222222lp you today?",
            sender: 'User'
        },
        {
            id: 5,
            text: "How can I help y3333333333333333ou today?",
            sender: 'Claude'
        },
      ]
    }
  },
  mutations: {
    toggleSidebar(state: State) {
      state.isCollapsed = !state.isCollapsed // 切换侧边栏收缩状态
    },
    ADD_MESSAGE(state, message: Message) {
      state.messages.push(message)
    }
  },
  actions: {
    toggleSidebar({ commit }: { commit: Commit }) {
      commit('toggleSidebar') // 提交 mutation 切换状态
    },
    sendMessage({ commit }, text: string) {
      const newMessage: Message = {
        id: Date.now(),
        text,
        sender: 'User'
      }
      commit('ADD_MESSAGE', newMessage)
    }
  },
  getters: {
    isCollapsed(state: State): boolean {
      return state.isCollapsed // 获取 isCollapsed 状态
    },
    allMessages: state => state.messages
  }
})

export default store
